// Created from GenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Reflection;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.Generated.AbstractMessage;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using TX = System.String;
using FT = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class RPA_I11 : AbstractMessage
    {
		/// Constructor
		public RPA_I11() : base()
        {
			if (MSH != null) {
                MSH.MessageType = new MSG() { MessageCode = "RPA", TriggerEvent = "I11" };
			}
        }

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("MSA",2)]
  	    [HL7Field(HL7Version.v23, 2, HL7Repeat.False, HL7Required.True,"MSA")]
	    public MSA MSA {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("RF1",4)]
  	    [HL7Field(HL7Version.v23, 4, HL7Repeat.False, HL7Required.False,"RF1")]
	    public RF1 RF1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("AUTHORIZATION",6)]
  	    [HL7Field(HL7Version.v23, 6, HL7Repeat.False, HL7Required.False,"AUTHORIZATION_RPA_I11")]
	    public AUTHORIZATION_RPA_I11 AUTHORIZATION {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PROVIDER",12)]
  	    [HL7Field(HL7Version.v23, 12, HL7Repeat.True, HL7Required.True,"PROVIDER_RPA_I11")]
	    public PROVIDER_RPA_I11[] PROVIDER {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PID",20)]
  	    [HL7Field(HL7Version.v23, 20, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("NK1",23)]
  	    [HL7Field(HL7Version.v23, 23, HL7Repeat.True, HL7Required.False,"NK1")]
	    public NK1[] NK1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("GT1",28)]
  	    [HL7Field(HL7Version.v23, 28, HL7Repeat.True, HL7Required.False,"GT1")]
	    public GT1[] GT1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("INSURANCE",31)]
  	    [HL7Field(HL7Version.v23, 31, HL7Repeat.False, HL7Required.False,"INSURANCE_RPA_I11")]
	    public INSURANCE_RPA_I11 INSURANCE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("ACC",43)]
  	    [HL7Field(HL7Version.v23, 43, HL7Repeat.False, HL7Required.False,"ACC")]
	    public ACC ACC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("DG1",47)]
  	    [HL7Field(HL7Version.v23, 47, HL7Repeat.True, HL7Required.False,"DG1")]
	    public DG1[] DG1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("DRG",52)]
  	    [HL7Field(HL7Version.v23, 52, HL7Repeat.True, HL7Required.False,"DRG")]
	    public DRG[] DRG {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("AL1",57)]
  	    [HL7Field(HL7Version.v23, 57, HL7Repeat.True, HL7Required.False,"AL1")]
	    public AL1[] AL1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PROCEDURE",60)]
  	    [HL7Field(HL7Version.v23, 60, HL7Repeat.True, HL7Required.True,"PROCEDURE_RPA_I11")]
	    public PROCEDURE_RPA_I11[] PROCEDURE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("RESULTS",69)]
  	    [HL7Field(HL7Version.v23, 69, HL7Repeat.False, HL7Required.False,"RESULTS_RPA_I11")]
	    public RESULTS_RPA_I11 RESULTS {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("VISIT",89)]
  	    [HL7Field(HL7Version.v23, 89, HL7Repeat.False, HL7Required.False,"VISIT_RPA_I11")]
	    public VISIT_RPA_I11 VISIT {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override Stack<string> ConsumeTextSegments(Stack<string> availableData, HL7ParserOptions options) {

				if (HL7Version.v23 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 RF1 = PopSegmentParseAndCheckRequired<RF1>(availableData, options, "RF1");
		 AUTHORIZATION = ProcessGroup<AUTHORIZATION_RPA_I11>(availableData, options, "AUTHORIZATION");
		 PROVIDER = ProcessGroupArray<PROVIDER_RPA_I11>(availableData, options, "PROVIDER");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 NK1 = PopSegmentParseAndCheckRequiredArray<NK1>(availableData, options, "NK1");
		 GT1 = PopSegmentParseAndCheckRequiredArray<GT1>(availableData, options, "GT1");
		 INSURANCE = ProcessGroup<INSURANCE_RPA_I11>(availableData, options, "INSURANCE");
		 ACC = PopSegmentParseAndCheckRequired<ACC>(availableData, options, "ACC");
		 DG1 = PopSegmentParseAndCheckRequiredArray<DG1>(availableData, options, "DG1");
		 DRG = PopSegmentParseAndCheckRequiredArray<DRG>(availableData, options, "DRG");
		 AL1 = PopSegmentParseAndCheckRequiredArray<AL1>(availableData, options, "AL1");
		 PROCEDURE = ProcessGroupArray<PROCEDURE_RPA_I11>(availableData, options, "PROCEDURE");
		 RESULTS = ProcessGroup<RESULTS_RPA_I11>(availableData, options, "RESULTS");
		 VISIT = ProcessGroup<VISIT_RPA_I11>(availableData, options, "VISIT");
		}
			if (availableData != null && availableData.Count > 0) {
				ConsumeZSegmentsFromText(availableData, options);
			}
            return availableData;
        
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "RPA_I11";
			}
        }

        static RPA_I11() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(RPA_I11));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
			if (MSH != null) {
				segmentData.Add(MSH.GetER7(options));
			}
			if (MSA != null) {
				segmentData.Add(MSA.GetER7(options));
			}
			if (RF1 != null) {
				segmentData.Add(RF1.GetER7(options));
			}
			if (AUTHORIZATION != null) {
				segmentData.Add(AUTHORIZATION.GetER7(options));
			}
			if (PROVIDER != null && PROVIDER.Length > 0) {
				for (int i = 0; i < PROVIDER.Length; i++) {
					segmentData.Add(PROVIDER[i].GetER7(options));
				}
			}
			if (PID != null) {
				segmentData.Add(PID.GetER7(options));
			}
			if (NK1 != null && NK1.Length > 0) {
				for (int i = 0; i < NK1.Length; i++) {
					segmentData.Add(NK1[i].GetER7(options));
				}
			}
			if (GT1 != null && GT1.Length > 0) {
				for (int i = 0; i < GT1.Length; i++) {
					segmentData.Add(GT1[i].GetER7(options));
				}
			}
			if (INSURANCE != null) {
				segmentData.Add(INSURANCE.GetER7(options));
			}
			if (ACC != null) {
				segmentData.Add(ACC.GetER7(options));
			}
			if (DG1 != null && DG1.Length > 0) {
				for (int i = 0; i < DG1.Length; i++) {
					segmentData.Add(DG1[i].GetER7(options));
				}
			}
			if (DRG != null && DRG.Length > 0) {
				for (int i = 0; i < DRG.Length; i++) {
					segmentData.Add(DRG[i].GetER7(options));
				}
			}
			if (AL1 != null && AL1.Length > 0) {
				for (int i = 0; i < AL1.Length; i++) {
					segmentData.Add(AL1[i].GetER7(options));
				}
			}
			if (PROCEDURE != null && PROCEDURE.Length > 0) {
				for (int i = 0; i < PROCEDURE.Length; i++) {
					segmentData.Add(PROCEDURE[i].GetER7(options));
				}
			}
			if (RESULTS != null) {
				segmentData.Add(RESULTS.GetER7(options));
			}
			if (VISIT != null) {
				segmentData.Add(VISIT.GetER7(options));
			}
           segmentData.AddRange(GetZSegmentsER7(options));
		   return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }


    }
}

